package cn.stacey.day08;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.junit.Test;

import cn.stacey.day07.Employee;


public class Demo {

	//List<Employee> list=new ArrayList<>();
	
	
	

	@Test
	public void test() {
		List list0=new ArrayList();
		list0.add("aaa");
		list0.add("zsed");
		Collections.sort(list0);
		System.out.println(list0);
		
		List<Employee> employee=new ArrayList<>();
		Employee e=new Employee("",17);
		Employee e0=new Employee("Java",18);
		employee.add(e);
		employee.add(e0);
		employee.add(e);
		e.setName("C++");
		e.setSalary(5000.0);
		
		employee.remove(e0);
		
		for(Employee content:employee) {
			System.out.println(content);
		}
		
		
		List<Employee> list=new ArrayList<>();
		Employee e1=new Employee("袁诗",10);
		list.add(e1);
		Employee e2=new Employee("张三",20);
		list.add(e2);
		
		Collections.sort(list,new Comparator<Employee>() {

			@Override
			public int compare(Employee e1, Employee e2) {
				// TODO Auto-generated method stub
				if(e1.getAge()>e2.getAge()) {
					return 1;
				}else if(e1.getAge()<e2.getAge()) {
					return -1;
				}
				return 0;
			}
			
			
		});
		
		//System.out.println(list);
	}
	
	
	@Test
	public void treeSet() {
		// 根据TreeSet创建时候，指定的比较器来排序
		Set<Employee> set=new TreeSet<>(new Comparator<Employee>() {

			@Override
			public int compare(Employee o1, Employee o2) {
				// TODO Auto-generated method stub
				return o1.getName().compareTo(o2.getName());
					
			}
			
		});
		set.add(new Employee("袁大头",13));
		set.add(new Employee("小花",10));
		
		Employee e1 = new Employee("swift", 18);
		Employee e2 = new Employee("d", 18);
		System.out.println(e2.equals(e1));
		
	}


}
